<extend name="Layout/ins_page" />
<block name="content">
	<select name="node_list" id="node_list" class="hidden">
		{:fill_option($node_list)}
	</select>
	{:W('PageHeader/simple',array('name'=>'菜单管理'))}
	<form id="form_search" name="form_search" method="post" action="" >
		<div class="oprator-panel">
			<select name="eq_pid" id="eq_pid" class="layui-input col-10">
				<option value="">全部</option>
				{:fill_option($groupList)}
			</select>
			<div class="split"></div>
			<a id="btn_add" class="btn">新增</a>
			<a id="btn_save"  class="btn">保存</a>
			<span class="l">|</span>
			<a id="btn_del"  class="btn btn-del">删除</a>
		</div>
	</form>
	<div class="sub-frame">
		<div class="sub-sidebar gray" style="height:528px;overflow-y:auto">
			{$menu}
		</div>
		<div class="sub-content gray">
			<form id="form_data" name="form_data" method="post" >
				<input type="hidden" name="id" id="id">
				<input type="hidden" name="ajax" id="ajax" value="1">
				<input type="hidden" name="opmode" id="opmode" value="">
				<div class="layui-sub-form-item ">
					<label class="layui-form-label" for="name">名称*：</label>
					<div class="layui-input-block">
						<input class="layui-input" type="text" id="name" name="name" check="required" info="请输入名称">
					</div>
				</div>

				<div class="layui-sub-form-item">
					<label class="layui-form-label" for="url">地址：</label>
					<div class="layui-input-block">
						<input class="layui-input" type="text" id="url" name="url">
					</div>
				</div>

				<div class="layui-sub-form-item">
					<label class="layui-form-label" for="url">父节点：</label>
					<div class="layui-input-block">
						<input name="node_name" class="layui-input" id="node_name" type="text"  readonly="readonly"/>
						<input name="pid"  id="pid" type="hidden" info="请选择父节点" check="required"  />
						<a class="add-on" id="btn_select_pid" > 选择 </a>
					</div>
				</div>
				<div class="layui-sub-form-item">
					<label class="layui-form-label" for="icon">图标：</label>
					<div class="layui-input-block">
						<input class="layui-input" type="text" id="icon" name="icon" >
					</div>
				</div>
				<div class="layui-sub-form-item">
					<label class="layui-form-label" for="badge_function">统计函数：</label>
					<div class="layui-input-block">
						<input class="layui-input" type="text" id="badge_function" name="badge_function" >
					</div>
				</div>
				<div class="layui-sub-form-item">
					<label class="layui-form-label" for="sort">排序：</label>
					<div class="layui-input-block col-10">
						<input class="layui-input" type="text" id="sort" name="sort" >
					</div>
				</div>

				<div class="layui-sub-form-item">
					<label class="layui-form-label" for="is_del">状态*：</label>
					<div class="layui-input-block x-select col-10">
						<select   name="is_del" id="is_del" class="layui-input">
							<option  value="0">启用</option>
							<option value="1">禁用</option>
						</select>
					</div>
				</div>
				<div class="layui-sub-form-item">
					<label class="layui-form-label" for="remark" >备注：</label>
					<div class="layui-input-block" >
						<textarea class="layui-textarea" id='remark' name="remark" rows="5" class="" ></textarea>
					</div>
				</div>
			</form>
		</div>
	</div>
</block>
<block name="js">
	<script type="text/javascript">
		layui.use(['global'], function() {
			var $ = layui.jquery;
			var layer = layui.layer;

			set_return_url(null);
			set_val('eq_pid', '{$eq_pid}');

			send_ajax("{:U('read')}", "id=" + "{$eq_pid}", function(data) {
				showdata(data);
			});

			$(".sub-sidebar .tree_menu a").click(function() {
				$(".sub-sidebar .tree_menu  a").each(function() {
					$(this).attr("class", "");
				});
				$(this).attr("class", "active");
				send_ajax("{:U('read')}", "id=" + $(this).attr("node"), function(data) {
					showdata(data);
				});
				return false;
			});

			function showdata(result) {
				for (var s in result.data) {
					set_val(s, result.data[s]);
				};
				$("#node_name").val($("#node_list option[value='" + $("#pid").val() + "']").text());
				$("#opmode").val("edit");
			};

			$('#eq_pid').on('change', function() {
				$('#form_search').submit();
			});

			//保存后关闭
			$('#btn_save').on('click', function() {
				send_form('form_data', '{:U("save")}', '', function(ret) {
					if (ret.status == 1) {
						layer.msg(ret.info, {
							time : 1200
						}, function() {
							location.reload(true);
						});
					} else {
						layer.msg(ret.info);
						return false;
					}
				});
			});

			$('#btn_select_pid').on('click', function() {
				winopen("{:U('winpop')}", 560, 470);
			});

			$("#btn_add").on('click', function() {
				winopen("{:U('add')}", 560, 470);
			});

			$('#btn_del').on('click', function() {
				if ($(".sub-sidebar a.active").length == 0) {
					layer.msg('请选择要删除的菜单');
					return false;
				}
				if ($(".sub-sidebar a.active").parent().find(".tree_menu").html() != undefined) {
					layer.msg('有子菜单不能删除');
					return false;
				}
				//信息框-例2
				layer.msg('确定要删除吗?', {
					time : 0,
					btn : ['确定', '取消'],
					yes : function(index) {
						var vars = $("#form_data").serialize();
						send_ajax("{:U('del')}", vars, function(ret) {
							if (ret.status) {
								layer.msg(ret.info, {
									time : 1200
								}, function() {
									location.reload(true);
								});
							}
						});
					},
					no : function(index) {
						layer.close(index);
					}
				});
			});
		});

	</script>
</block>